package com.cyx.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertiesServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Properties properties = new Properties();
        InputStream stream = getServletContext().getResourceAsStream("/WEB-INF/classes/db.properties");
        try{
            properties.load(stream);
        }finally {
            stream.close();
        }

        resp.getWriter().printf("username=%s,password=%s",
                properties.getProperty("username"),
                properties.getProperty("password"));



    }

}
